﻿
using System;
using System.Web;
using System.Collections.Generic;
using BLToolkit.Mapping;
using BLToolkit.Data;
using BLToolkit.Reflection;

/// <summary>ID</summary>
public class TripRule : LoggingObject
{
	public TripRule()
	{
		bus = new Bus();
		route = new Route();
		tripRulePeriod = new TripRulePeriod();
	}
	/// <summary>ID</summary>
	[Nullable]
	[MapField("TripRule_id")]
	public Int64 Id { get; set; }

	/// <summary>id автобуса</summary>
	[Nullable]
	public Int64 Bus_id { get { return bus.Id; } }
	/// <summary>автобус</summary>
	[Nullable]
	public Bus bus { get; set; }

	/// <summary>id маршрута</summary>
	[Nullable]
	public Int64 Route_id { get { return route.Id; } }
	/// <summary>маршрут</summary>
	[Nullable]
	public Route route { get; set; }

	/// <summary>Время отправления</summary>
	[Nullable]
	[MapField("TripRule_Time")]
	public DateTime Time { get; set; }

	/// <summary>Дата начала действия правила</summary>
	[Nullable]
	[MapField("TripRule_StartDT")]
	public DateTime StartDT { get; set; }

	/// <summary>Дата конца действия правила</summary>
	[Nullable]
	[MapField("TripRule_EndDT")]
	public DateTime? EndDT { get; set; }

	/// <summary>id правила следования N через M</summary>
	[Nullable]
	public Int64 TripRulePeriod_id { get { return tripRulePeriod.Id; } }
	/// <summary>правило следования N через M</summary>
	[Nullable]
	public TripRulePeriod tripRulePeriod { get; set; }

	/// <summary>Четные/нечетные дни следования</summary>
	[MapField("TripRule_Even")]
	public bool? Even { get; set; }


	public bool Merge()
	{
		try
		{
			SetLoggingInfo();
			this.Id = DBEntity<TripRule>.Merge(this);
			return true;
		}
		catch (Exception e) { return false; }
	}
}
